#include "AppState.h"
#include "AppStateManager.h"
#include "Mandelbrot.h"
#include "Parameters.h"
#include "stdincl.h"

AppStateMandelbrot::AppStateMandelbrot()    {}

AppStateMandelbrot::~AppStateMandelbrot()   {}

void AppStateMandelbrot::OnActivate()
{
    //
}

void AppStateMandelbrot::OnDeactivate()
{
    //
}

void AppStateMandelbrot::OnLoop(sf::RenderWindow& window)
{
    window.clear(sf::Color(120, 120, 120, 255));

    /**
    *   The following block of code is to test how coloring pixels actually works.
    */

    sf::Texture texture;
    texture.create(Parameters::GetScreenWidth(), Parameters::GetScreenHeight());

    Mandelbrot fractal;
    fractal.Allocate();
    fractal.Iterate();

    texture.update(fractal.GetPixelArray());
    fractal.Deallocate();
    sf::Sprite sprite(texture);
    window.draw(sprite);

    /**
    *   Block of code ends.
    */

    window.display();

    sf::Event event;
    while (true)
    {
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::MouseButtonPressed)
            {
                AppStateManager::GetInstance()->SetActiveAppState(AppState::SplashScreen);
                return;
            }

            if (event.type == sf::Event::Closed)
                window.close();
                return;
        }
    }
}
